import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:wanxiang_app/bean/normal_entity.dart';
import 'package:wanxiang_app/bean/qa_list_entity.dart';
import 'package:wanxiang_app/pages/home/qaDetail.dart';
import 'package:wanxiang_app/utils/constant.dart';
import '../../bean/service_list_entity.dart';
import '../../utils/network_manager.dart';
import '../../utils/network_url.dart';
import '../../utils/toast_util.dart';
import '../../widgets/myappbar.dart';
import 'package:get/get.dart';

class NoticeDetailController extends GetxController{

  @override
  void onInit() {
    super.onInit();
    id = Get.arguments;
    _getService();
  }
  @override
  void onClose() {
    super.onClose();
  }
  String id = '';
  List<QaListData> list = [];
  void _getService(){
    DioManager.getInstance().post(ServiceUrl.noticeList, {
      "details_id":id
    }, (data) async {
      QaListEntity bannerEntity = QaListEntity.fromJson(jsonDecode(data));
      list = bannerEntity.data;
      update();
    }, (error) {
      ToastUtil.show(error);
    });
  }
}


class NoticeDetailPage extends GetView<NoticeDetailController>  {
  late NoticeDetailController controller ;
  late BuildContext context ;
  @override
  Widget build(BuildContext context1) {
    Get.lazyPut<NoticeDetailController>(() => NoticeDetailController());
    controller = Get.find();
    context = context1;

    return GetBuilder<NoticeDetailController>(
      builder: (_){
        return  Scaffold(
            appBar: MyAppBar(context: context, title: '公告详情',hasLeading: true,),
            backgroundColor: Colors.white,
            body: controller.list.isEmpty?Container(): _content());
      },
    )
    ;

  }
  Widget _content(){
    return SingleChildScrollView(
        child: Container(
          padding: EdgeInsets.only(left: 20.w,top: 20.h,right: 20.w,bottom: 20.h),
          child: Column(
            children: [
              _top(),
              Html(data: controller.list[0].content,style: {
              },
              )
            ],
          ),
        )
    ) ;
  }



  Widget _top(){
    return Container(
      width: Get.width - 50.w,
      margin: EdgeInsets.fromLTRB(15.w, 30.h, 15.w, 20.h),
      padding: EdgeInsets.all(10.w),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(8.r),
            gradient: const LinearGradient(      //渐变位置
                begin: Alignment.centerLeft, //右上
                end: Alignment.centerRight, //左下
                //渐变颜色[始点颜色, 结束颜色]
                colors: [Color(0xFF7BA7FE), Color(0xFF4BA5FF),Color(0xFF7BAFFE)]
            )

    ),
    
    child: Text(controller.list[0].title,style: const TextStyle(
      color: Colors.white,
    ),),
    );
  }





}